package cn.z2huo.demo.redis.spring.test;

import cn.z2huo.demo.redis.spring.SpringDataRedisSpringBootApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
@Disabled
@Slf4j
@SpringBootTest(classes = SpringDataRedisSpringBootApplication.class)
public class RedisClusterConnectionTest2 {

    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Test
    public void test() {
        RedisClusterConnection connection = redisConnectionFactory.getClusterConnection();

        connection.set("thing1".getBytes(StandardCharsets.UTF_8), "value1".getBytes(StandardCharsets.UTF_8));
        connection.set("{thing1}.thing2".getBytes(StandardCharsets.UTF_8), "value12".getBytes(StandardCharsets.UTF_8));
        connection.set("thing2".getBytes(StandardCharsets.UTF_8), "value2".getBytes(StandardCharsets.UTF_8));

        List<byte[]> thingResult = connection.mGet("thing1".getBytes(StandardCharsets.UTF_8), "{thing1}.thing2".getBytes(StandardCharsets.UTF_8));
        System.out.println(thingResult.stream().map(String::new).toList());

        List<byte[]> thingResult2 = connection.mGet("thing1".getBytes(StandardCharsets.UTF_8), "thing2".getBytes(StandardCharsets.UTF_8));
        System.out.println(thingResult2.stream().map(String::new).toList());
    }
}
